<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\StoreController\doRule;
use App\Services\Admin\Store;
use Illuminate\Http\Request;

class StoreController extends Controller
{
    public function index()
    {
        $result = [
            'result'=>Store::lists(),
            'sear_value'=>\request()->get('sear_value'),
        ];

        return view('admin.store.index', $result);
    }

    public function add()
    {
        $result = [

        ];

        return view('admin.store.edit',$result);
    }

    public function edit(Request $request, $id)
    {
        $result = [
            'id'=>$id,
            'result'=> Store::info($id),
        ];

        return view( 'admin.store.edit', $result);
    }

    public function do(doRule $request)
    {
        if ($request->ajax()) {

            $input = $request->all();

            if (empty($input['id'])) {
                unset($input['id']);
                Store::add($input);
            } else {
                Store::edit($input['id'],$input);
            }

            return self::success([]);
        }
    }
}
